<template>
  <div class="icons">
    <swiper :options="swiperOption" v-if="icons.length">
      <swiper-slide v-for="(item, index) of pages" :key="index">
        <div class="icon" v-for="list in item" :key="list.id">
          <div class="icon-img">
            <img class="icon-img-con" :src="list.imgUrl" alt="">
            <p>{{ list.desc }}</p>
          </div>
        </div>
      </swiper-slide>
      <!--<div class="swiper-pagination"  slot="pagination"></div>-->
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'Icons',
  props: {
    icons: Array
  },
  data () {
    return {
      swiperOption: {
        // pagination: '.swiper-pagination'
        autoplay: false
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      let listLength = Math.ceil(this.icons.length / 8)// 设置轮播次数
      for (let i = 0; i < listLength; i++) {
        pages[i] = []
      }
      this.icons.forEach(function (value, index) {
        const page = Math.floor(index / 8)
        pages[page].push(value)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import "~styles/varibles.styl"
  @import "~styles/mixins.styl"
  .icons >>> .swiper-container
    padding-top: 1%
    height: 0
    padding-bottom: 50%
  .icon
    position: relative
    overflow: hidden
    /*相对于父级元素的width*/
    width: 25%
    float: left
    height: 0
    /*相对于父级元素的width*/
    padding-bottom 25%
    .icon-img
      position: absolute
      top:4px
      left: 10px
      bottom: .4rem
      box-sizing border-box
      .icon-img-con
        height: 100%
    p
      text-align: center
      margin-top 2px
      color: $darkTextColor
      ellipsis()
</style>
